package org.shunfeng.dao.impl;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.shunfeng.dao.UserDao;
import org.shunfeng.pojo.SysUser;
import org.shunfeng.utils.DruidUtils;

import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    private QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
    @Override
    public SysUser login(String username, String password) throws SQLException {
        String sql = "select id,username,password,nickname from sys_user where username = ? and password = ?";
        return qr.query(sql, new BeanHandler<SysUser>(SysUser.class), username, password);
    }

    @Override
    public SysUser confirmPassword(String uId, String password) throws SQLException {
        String sql = "select * from sys_user where id = ? and password = ?";
        return qr.query(sql, new BeanHandler<SysUser>(SysUser.class), uId, password);
    }
    @Override
    public int updatePassword(String Uid, String password) throws SQLException{
        String sql = "update sys_user set password = ? where id = ?";
        return qr.update(sql, password, Uid);

    }
}
